package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> pageNursingLevel(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                         @ApiParam("每页大小") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                         @ApiParam("护理等级名称") @RequestParam(value = "name", required = false) String name,
                                                                         @ApiParam("护理等级状态") @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.pageNursingLevel(pageNum, pageSize, name, status);
        return ResponseResult.success(pageResponse);
    }

    @ApiOperation("新增")
    @PostMapping("/insert")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getNursingLevelById(@PathVariable(value = "id") Integer id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteNursingLevel(@PathVariable(value = "id") Integer id) {
        nursingLevelService.deleteNursingLevel(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult forbiddenNursingLevel(@PathVariable(value = "id") Integer id,
                                                @PathVariable(value = "status") Integer status) {
        nursingLevelService.forbiddenNursingLevel(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult<List<NursingLevelVo>> getAllNursingLevel() {
        List<NursingLevelVo> levelVos = nursingLevelService.getAllNursingLevel();
        return ResponseResult.success(levelVos);
    }
}
